﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>frmTraPer</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dtTK = MakeTable();
            //doan nay co the bo 
            //List<QLNS.tkTDDT_CBCC> lstTK = QLNS.Models.TKTDDT_CBCCModels.GetAll();
            //foreach (var r in lstTK)
            //{
            //    System.Data.DataRow row;row = dtTK.NewRow();
            //    this.FillDataRow(row, r);
            //    dtTK.Rows.Add(row);
            //}
            
            //Tao 5 level cho phong ban
            List<QLNS.tkTDDT_CBCC> root = QLNS.Models.TKTDDT_CBCCModels.GetAllChild(0);
            if (root.Count > 0)
            {
                //Cap 1 la Don vi       
                foreach (var r in root)
                {
                    //listRootDept.Add(new SelectListItem { Value = r.ID.ToString(), Text = r.TenPhongBan });
                    System.Data.DataRow row; row = dtTK.NewRow();
                    this.FillDataRow(row, r, r.ID.ToString(), "0","0","0","0");
                    dtTK.Rows.Add(row);
                    List<QLNS.tkTDDT_CBCC> root1 = QLNS.Models.TKTDDT_CBCCModels.GetAllChild(r.ID);
                    if (root1.Count > 0)
                    {
                        foreach (var r1 in root1)
                        {
                            //listRootDept.Add(new SelectListItem { Value = r1.ID.ToString(), Text = "- " + r1.TenPhongBan });
                            System.Data.DataRow row1; row1 = dtTK.NewRow();
                            this.FillDataRow(row1, r1, r.ID.ToString(), r1.ID.ToString(), "0", "0", "0");
                            dtTK.Rows.Add(row1);
                            List<QLNS.tkTDDT_CBCC> root2 = QLNS.Models.TKTDDT_CBCCModels.GetAllChild(r1.ID);
                            if (root2.Count > 0)
                            {
                                foreach (var r2 in root2)
                                {
                                    //listRootDept.Add(new SelectListItem { Value = r2.ID.ToString(), Text = "- - " + r2.TenPhongBan });
                                    System.Data.DataRow row2; row2 = dtTK.NewRow();
                                    this.FillDataRow(row2, r2, r.ID.ToString(), r1.ID.ToString(), r2.ID.ToString(), "0", "0");
                                    dtTK.Rows.Add(row2);
                                    List<QLNS.tkTDDT_CBCC> root3 = QLNS.Models.TKTDDT_CBCCModels.GetAllChild(r2.ID);
                                    if (root3.Count > 0)
                                    {
                                        foreach (var r3 in root3)
                                        {
                                            //listRootDept.Add(new SelectListItem { Value = r3.ID.ToString(), Text = "- - - " + r3.TenPhongBan });
                                            System.Data.DataRow row3; row3 = dtTK.NewRow();
                                            this.FillDataRow(row3, r3, r.ID.ToString(), r1.ID.ToString(), r2.ID.ToString(), r3.ID.ToString(), "0");
                                            dtTK.Rows.Add(row3);
                                            List<QLNS.tkTDDT_CBCC> root4 = QLNS.Models.TKTDDT_CBCCModels.GetAllChild(r3.ID);
                                            if (root4.Count > 0)
                                            {
                                                foreach (var r4 in root4)
                                                {
                                                    //listRootDept.Add(new SelectListItem { Value = r4.ID.ToString(), Text = "- - - - " + r4.TenPhongBan });
                                                    System.Data.DataRow row4; row4 = dtTK.NewRow();
                                                    this.FillDataRow(row4, r4, r.ID.ToString(), r1.ID.ToString(), r2.ID.ToString(), r3.ID.ToString(), r4.ID.ToString());
                                                    dtTK.Rows.Add(row4);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_ThongkeTDDT_BoiDuongCBCC.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (dtTK != null && dtTK.GetType().ToString() != "System.String")
                rd.SetDataSource(dtTK);


            CrystalReportViewer1.ReportSource = rd;
            
        }
        private void FillDataRow(System.Data.DataRow row, QLNS.tkTDDT_CBCC r, string lev1, string lev2, string lev3, string lev4, string lev5)
        {
            //System.Data.DataRow row = new System.Data.DataRow();
            row["lev1"] = lev1;
            row["lev2"] = lev2;
            row["lev3"] = lev3;
            row["lev4"] = lev4;
            row["lev5"] = lev5;
            row["ID"] = r.ID;
            row["TenPhongBan"] = r.TenPhongBan;
            row["soluong"] = r.soluong;
            row["VH1010"] = r.VH1010;
            row["VH1212"] = r.VH1212;
            row["SoCap"] = r.SoCap;
            row["TrungCap"] = r.TrungCap;
            row["CaoDang"] = r.CaoDang;
            row["DaiHoc"] = r.DaiHoc;
            row["ThacSi"] = r.ThacSi;
            row["Tiensi"] = r.TienSi;
            row["Tiensikhoahoc"] = r.Tiensikhoahoc;
            row["Can su"] = r.Can_su;
            row["Chuyen vien"] = r.Chuyen_vien;
            row["Chuyen vien chinh"] = r.Chuyen_vien_chinh;
            row["Chuyen vien cao cap"] = r.Chuyen_vien_cao_cap;
            row["A"] = r.A;
            row["B"] = r.B;
            row["C"] = r.C;
            row["D"] = r.D;
            row["tinhocA"] = r.tinhocA;
            row["tinhocB"] = r.tinhocB;
            row["tinhocC"] = r.tinhocC;
            row["llsocap"] = r.llsocap;
            row["lltrungcap"] = r.lltrungcap;
            row["llcaocap"] = r.llcaocap;
            row["PhanLoai"] = r.PhanLoai;

            //return row;
        }
        private System.Data.DataTable MakeTable()
        {
            // Create a new DataTable.
            System.Data.DataTable table = new System.Data.DataTable("Table");

            // Declare variables for DataColumn and DataRow objects.
            System.Data.DataColumn column;

            // Create new DataColumn, set DataType, 
            // ColumnName and add to DataTable.    
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ID";
            column.Unique = true;
            // Add the Column to the DataColumnCollection.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "lev1";
            column.Caption = "level 1";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "lev2";
            column.Caption = "level 2";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "lev3";
            column.Caption = "level 3";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "lev4";
            column.Caption = "level 4";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "lev5";
            column.Caption = "level 5";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenCoQuan";
            column.Caption = "Đơn vị";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenPhongBan";
            column.Caption = "Phòng Ban";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "soluong";
            column.Caption = "Số lượng";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "VH1010";
            column.Caption = "10/10";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "VH1212";
            column.Caption = "12/12";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "SoCap";
            column.Caption = "Sơ cấp";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TrungCap";
            column.Caption = "Trung cấp";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "CaoDang";
            column.Caption = "Cao đẳng";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "DaiHoc";
            column.Caption = "Đại học";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ThacSi";
            column.Caption = "Thạc sỹ";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Tiensi";
            column.Caption = "Tiến sỹ";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Tiensikhoahoc";
            column.Caption = "Tiến sỹ khoa học";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Can su";
            column.Caption = "Cán sự";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Chuyen vien";
            column.Caption = "Chuyên viên";
            // Add the column to the table.
            table.Columns.Add(column);
            
            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Chuyen vien chinh";
            column.Caption = "Chuyên viên chính";
            // Add the column to the table.
            table.Columns.Add(column);
            
            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Chuyen vien cao cap";
            column.Caption = "Chuyên viên cao cấp";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "A";
            column.Caption = "A";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "B";
            column.Caption = "B";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "C";
            column.Caption = "C";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "D";
            column.Caption = "D";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "tinhocA";
            column.Caption = "A";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "tinhocB";
            column.Caption = "B";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "tinhocC";
            column.Caption = "C";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "llsocap";
            column.Caption = "Lý luận sơ cấp";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "lltrungcap";
            column.Caption = "Lý luân trung cấp";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "llcaocap";
            column.Caption = "Lý luân cao cấp";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "PhanLoai";
            column.Caption = "Phân loại";
            // Add the column to the table.
            table.Columns.Add(column);
            
            
            
            // Make the ID column the primary key column.
            System.Data.DataColumn[] PrimaryKeyColumns = new System.Data.DataColumn[1];
            PrimaryKeyColumns[0] = table.Columns["ID"];
            table.PrimaryKey = PrimaryKeyColumns;
            return table;
        }
    </script>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
            AutoDataBind="true" ToolPanelView="None" />
    </div>
    </form>
</body>
</html>
